#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1e5 + 10;

int n, m, t;
int row[N], col[N];

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m >> t;

    for(int i = 1, x, y; i <= t; i ++){
        cin >> x >> y;
        row[x] ++, col[y] ++;
    }

    if(t % n == 0 && t % m == 0){
        cout << "both ";
    }else if(t % n != 0 && t % m != 0){
        cout << "impossible" << '\n';
    }else if(t )


    return 0;
}